package pl.edu.pw.elka.tinyrepo.client.common;

import java.util.ArrayList;

import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

/**
 * Model drzewiastej stuktury repozytorium
 * 
 * @author Anna Stępień
 * @version 13-12-2011
 *
 */
public class RepoTreeModel implements TreeModel
{
	private ArrayList<FileNode> files;
	private ArrayList<DirNode> dirs;
	private DefaultMutableTreeNode root;
	
	public RepoTreeModel(final String baseDirName, final ArrayList<String> dirs, final ArrayList<String> files)
	{
		root = new DefaultMutableTreeNode(baseDirName);
		
		this.files = new ArrayList<FileNode>();
		for (String string : files) 
		{
			DefaultMutableTreeNode node = new FileNode(string);
			this.files.add((FileNode) node);
			root.add(node);
		}
		this.dirs = new ArrayList<DirNode>();
		for (String string : dirs) 
		{
			DefaultMutableTreeNode node = new DirNode(string);
			this.dirs.add((DirNode) node);
			root.add(node);
		}
		
	}

	@Override
	public void addTreeModelListener(TreeModelListener arg0)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public Object getChild(Object parent, int index)
	{
		return ((MutableTreeNode)parent).getChildAt(index);
	}

	@Override
	public int getChildCount(Object parent)
	{
		return ((MutableTreeNode)parent).getChildCount();
	}

	@Override
	public int getIndexOfChild(Object parent, Object child)
	{
		return ((MutableTreeNode)parent).getIndex((TreeNode)child);
	}

	@Override
	public Object getRoot()
	{
		return root;
	}

	@Override
	public boolean isLeaf(Object node)
	{
		return ((MutableTreeNode)node).isLeaf();
	}

	@Override
	public void removeTreeModelListener(TreeModelListener arg0)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void valueForPathChanged(TreePath arg0, Object arg1)
	{
		// TODO Auto-generated method stub

	}

}
